using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace Hanoi
{
    public class FormProfiles : Hanoi.FormOptions
    {
        private ListView lvProfiles;
        private ColumnHeader nameColumn;
        private System.ComponentModel.IContainer components = null;

        public FormProfiles()
        {
            // This call is required by the Windows Form Designer.
            InitializeComponent();
            base.ResizeChildComponents();
            // TODO: Add any initialization after the InitializeComponent call
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        #region Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem();
            System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem();
            System.Windows.Forms.ListViewItem listViewItem3 = new System.Windows.Forms.ListViewItem();
            System.Windows.Forms.ListViewItem listViewItem4 = new System.Windows.Forms.ListViewItem();
            this.lvProfiles = new System.Windows.Forms.ListView();
            this.nameColumn = new System.Windows.Forms.ColumnHeader();
            // 
            // mnuPrevious
            // 
            this.mnuPrevious.Text = "Exit";
            this.mnuPrevious.Click += new System.EventHandler(this.mnuPrevious_Click);
            // 
            // mnuNext
            // 
            this.mnuNext.Click += new System.EventHandler(this.mnuNext_Click);
            // 
            // pnOptions
            // 
            this.pnOptions.Controls.Add(this.lvProfiles);
            // 
            // lblInfo
            // 
            this.lblInfo.Font = new System.Drawing.Font("Nina", 8F, System.Drawing.FontStyle.Regular);
            this.lblInfo.Text = "Choose one of the profiles available and see its full description...";
            // 
            // lvProfiles
            // 
            this.lvProfiles.Activation = System.Windows.Forms.ItemActivation.OneClick;
            this.lvProfiles.Columns.Add(this.nameColumn);
            this.lvProfiles.Font = new System.Drawing.Font("Nina", 10F, System.Drawing.FontStyle.Regular);
            this.lvProfiles.FullRowSelect = true;
            this.lvProfiles.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
            listViewItem1.Text = "Last used";
            listViewItem2.Text = "Classic";
            listViewItem3.Text = "Random";
            listViewItem4.Text = "Custom...";
            this.lvProfiles.Items.Add(listViewItem1);
            this.lvProfiles.Items.Add(listViewItem2);
            this.lvProfiles.Items.Add(listViewItem3);
            this.lvProfiles.Items.Add(listViewItem4);
            this.lvProfiles.Location = new System.Drawing.Point(0, 0);
            this.lvProfiles.Size = new System.Drawing.Size(176, 115);
            this.lvProfiles.View = System.Windows.Forms.View.Details;
            this.lvProfiles.SelectedIndexChanged += new System.EventHandler(this.lvProfiles_SelectedIndexChanged);
            // 
            // nameColumn
            // 
            this.nameColumn.Text = "Profile Name";
            this.nameColumn.Width = 160;
            // 
            // FormProfiles
            // 
            this.ClientSize = new System.Drawing.Size(176, 180);
            this.Text = "Profiles - Hanoi";
            this.Closed += new System.EventHandler(this.FormProfiles_Closed);
            this.Activated += new System.EventHandler(this.FormProfiles_Activated);

        }
        #endregion

        private void lvProfiles_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(lvProfiles.SelectedIndices.Count > 0)
            {
                int index = lvProfiles.SelectedIndices[0];
                ShowDescription(index);
            }

        }

        private void ShowDescription(int index)
        {
            string t;
            switch (index)
            {
                case 0:
                    t = "Last used profile. It retrieves the profile used last time you played.";
                    break;
                case 1:
                    t = "The classic version of Hanoi. You have to move all disks from tower one to the third tower in less movement possible.";
                    break;
                case 2:
                    t = "It chooses any random option available and games this way may be so exciting.";
                    break;
                case 3:
                    t = "Feel free to navigate inside games' options and tweak it until it's fine for you. There is a lot of options that you were never aware of.";
                    break;

                default:
                    t = "No description available this time.";
                    break;
            }
            lblInfo.Text = t;
        }

        private void mnuNext_Click(object sender, EventArgs e)
        {
            if (lvProfiles.SelectedIndices.Count > 0)
            {
                int index = lvProfiles.SelectedIndices[0];
                UseProfile(index);
            }
        }

        private void UseProfile(int index)
        {
            Hanoi.Logic.IGame t = null;
            Form formNext = null;
            switch (index)
            {
                case 0:
                    t = Hanoi.Logic.Profiles.LastProfile.Get();
                    break;
                case 1:
                    t = new Hanoi.Logic.Profiles.ClassicProfile();
                    break;
                case 2:
                    t = new Hanoi.Logic.Profiles.RandomProfile();
                    break;
                case 3:
                    t = new Hanoi.Logic.Profiles.CustomProfile();
                    break;

                default:
                    
                    break;
            }

            Hanoi.Logic.Profiles.LastProfile.Set(t);
            if (index < 3)
                formNext = new Hanoi.FormMain(t, this);
            else
                formNext = new FormDiskNumber(this, (Hanoi.Logic.Profiles.CustomProfile)t);

            formNext.ShowDialog();
        }

        public void ShowForm(Hanoi.Logic.IGame game)
        {
            (new Hanoi.FormMain(game, this)).ShowDialog();
            this.Focus();
            this.lvProfiles.Focus();
        }

        private void FormProfiles_Activated(object sender, EventArgs e)
        {
            lvProfiles.Focus();
        }

        private void mnuPrevious_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FormProfiles_Closed(object sender, EventArgs e)
        {
            Application.Exit();
        }
        
    }
}
